package cn.whitecao.agent.core.model;



import cn.hutool.core.lang.UUID;
import cn.whitecao.agent.core.config.ConfigContext;
import cn.whitecao.agent.core.utils.IDGenerator;
import lombok.Data;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 采集数据的实体类
 *
 * @author Bashful Huang
 * @since 2020-09-11
 **/
@Data
public class TraceModel {
    /**
     * 当前的线程traceId
     * 多节点的时候需要获取上个节点的traceId
     */
    private String traceId;

    /**
     * 顺序 考虑是否需要用多线程的AtomicInteger
     * 多节点的时候需要获取上个节点的sequenceNumber
     * 手动自增
     */
    private AtomicInteger sequenceNumber;


    private String spanId;

    private String parentSpanId;

    /**
     * 多节点时候的节点名
     */
    private String appName="default";



    public TraceModel(String traceId,String parentSpanId) {
        this.traceId = traceId;

    }

    public TraceModel() {

        this.traceId = IDGenerator.getId();
        this.sequenceNumber = new AtomicInteger(0);
        this.appName =ConfigContext.getStr( "appName","default");
    }

    public Integer incAndGetSequenceNumber() {
        return sequenceNumber.addAndGet(1);
    }

//    public Integer increase(){
//        return ++this.sequenceNumber;
//    }




}